package com.wanyin.cloud.api;

import com.wanyin.cloud.common.response.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("api")
@RefreshScope
public class HelloApi {

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping("hello/{name}")
    public ResultVO hello(@PathVariable String name) {
        log.debug("hello test");
        return ResultVO.success("welcome " + name + " to cloud 2022," + LocalDateTime.now() + "port:" + serverPort);
    }

    @Value("${defaultname}")
    private String defaultName;

    @GetMapping("getDefaultName")
    public String getDefaultName() {
        return defaultName;
    }
}
